package com.example.musicbox.controller;


import com.example.musicbox.entity.MMessage;
import com.example.musicbox.service.impl.MMessageServiceImpl;
import com.example.musicbox.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 帅哥是我
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/m-message")
public class MMessageController {

    @Resource
    private MMessageServiceImpl mMessageService;


    /**
     * @api {POST} /m-message/insertMessage 发送消息
     * @apiVersion 1.0.0
     * @apiGroup 消息控制器
     * @apiName insertMessage
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=X1JnANM3P
     * @apiParam (请求体) {Number} mid
     * @apiParam (请求体) {Number} senduserid
     * @apiParam (请求体) {Number} acceptuserid
     * @apiParam (请求体) {String} sendtype
     * @apiParam (请求体) {String} detailinfo
     * @apiParam (请求体) {String} mstatus
     * @apiParam (请求体) {String} sendusername
     * @apiParam (请求体) {Object} sendDate
     * @apiParam (请求体) {Number} musicId
     * @apiParamExample 请求体示例
     * {"musicId":5269,"sendusername":"Msj","senduserid":3961,"acceptuserid":2988,"mid":424,"mstatus":"ABs02eJ","sendtype":"6d3R","detailinfo":"bNNmz"}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/insertMessage")
    public Result insertMessage(@RequestBody MMessage mMessage,@RequestHeader String token){
        return mMessageService.insertMessage(mMessage,token);
    }


    /**
     * @api {POST} /m-message/deleteMessage 删除消息
     * @apiVersion 1.0.0
     * @apiGroup 消息控制器
     * @apiName deleteMessage
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=0T
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     "id":1
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/deleteMessage")
    public Result deleteMessage(@RequestBody Map map,@RequestHeader String token)
    {
        Integer id = (Integer) map.get("id");
        return mMessageService.deleteMessage(id,token);
    }


    /**
     * @api {POST} /m-message/selectById 根据id查询消息
     * @apiVersion 1.0.0
     * @apiGroup 消息控制器
     * @apiName selectById
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=XDlhgqqM
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     “id”:1
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectById")
    public Result selectById(@RequestBody Map map, @RequestHeader String token)
    {
        Integer id = (Integer) map.get("id");
        return mMessageService.selectById(id,token);
    }


    /**
     * @api {POST} /m-message/selectByList 查询用户目录和目录里面的歌曲列表
     * @apiVersion 1.0.0
     * @apiGroup 消息控制器
     * @apiName selectByList
     * @apiParam (请求参数) {String} token
     * @apiParamExample 请求参数示例
     * token=fYCcszECAj
     * @apiParam (请求体) {Object} requestBody
     * @apiParamExample 请求体示例
     * {
     *     “p”:1,
     *     "s":10
     * }
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * {}
     */
    @PostMapping("/selectByList")
    public Result selectByList(@RequestHeader String token,@RequestBody Map map)
    {
        Integer p = (Integer) map.get("p");
        Integer s = (Integer) map.get("s");
        return mMessageService.selectByList(token,p,s);
    }

}

